<!-- subpkg_consult/department/index.vue -->
<script lang="ts" setup>
  import { departmentListApi } from '../../apis/consult'
  import { DepartData } from '../../types/consult'
  import { ref } from 'vue'
  import { useConsultStore } from '@/stores/counter'

  const props = defineProps<{ illnessType: string }>()
  const store = useConsultStore()
  store.setIllnessType(props.illnessType)

  const topList = ref<DepartData[]>([])
  const activeIndex = ref(0)
  const getList = async () => {
    const res = await departmentListApi()
    // console.log(res)
    topList.value = res
  }
  getList()
</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <view
        v-for="(item, index) in topList"
        :key="item.id"
        class="department-item"
        :class="{ active: activeIndex === index }"
        @click="activeIndex = index"
        >{{ item.name }}</view
      >
    </scroll-view>
    <scroll-view class="department-secondary">
      <navigator
        v-for="item in topList[activeIndex].child"
        :key="item.id"
        hover-class="none"
        :url="`/subpkg_consult/description/index?depId=${item.id}`"
        class="department-item"
      >
        {{ item.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
  @import './index.scss';
</style>
